<?php
/**
 * @since 27.08.2011
 * @author Akulov Denis <akulov.d.g@gmail.com>
 */
class MVC_View_Hook_Container implements MVC_View_Hook_Container_Interface {

    private $_objConfig;


    private $_arInsertHooks = array();


    private $_arAddHooks = array();


    public function __construct (Config_Interface $objConfig) {
        $this->_objConfig = $objConfig;
    }


    public function addHookInsert ($strHookName ,$strHookFile) {
        $objHook = $this->_createHook($strHookName, $strHookFile);

        if (array_key_exists($strHookName, $this->_arInsertHooks)) {
            throw new Exception('"Inset hook" is duplicate : '.$strHookName);
        }

        $this->_arInsertHooks[$strHookName] = $objHook;

        return $objHook;
    }


    public function addHookAdd ($strHookName, $strHookFile) {
        $objHook = $this->_createHook($strHookName, $strHookFile);

        $this->_arAddHooks[] = $objHook;

        return $objHook;
    }


    public function render ($strContent) {
        /* @var $objInsertHook MVC_View_Hook_Element_Interface */
        foreach ($this->_arInsertHooks as $objInsertHook) {
            $strContent = $objInsertHook->renderAsInsertHook($strContent);
        }

        /* @var $objAddHook MVC_View_Hook_Element_Interface */
        foreach ($this->_arAddHooks as $objAddHook) {
            $strContent = $objAddHook->renderAsAddHook($strContent);
        }

        return $strContent;
    }


    private function _createHook ($strHookName, $strHookFile) {
        return new MVC_View_Hook_Element($strHookName, $strHookFile, $this->_objConfig);
    }

}